package com.zx.deploy.common.utils;



import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import com.zx.deploy.common.exception.BusinessException;

public class CommonUtil {
	protected static Logger log = LogManager.getLogger(CommonUtil.class);

	/**
	 * 
	 * @Description: 通用异常处理
	 * @param obj
	 *            当前controller
	 * @param log
	 *            日志对象
	 * @param ex
	 *            异常对象
	 * @param returnObj
	 *            返回jsonmodel
	 * @param msg
	 *            输出信息
	 * @throws @author
	 *             jbyu
	 */
	public static void exceptionProcess(Logger log, Exception ex, ReturnModel returnObj, String msg) {
		returnObj.setInfo(false, msg);
		if (ex instanceof BusinessException) {
			returnObj.setInfo(false, ex.getMessage());
		}
		log.error(msg + ":" + ex.getMessage(), ex);
	}

	/**
	 * 睡眠
	 * 
	 * @param millis
	 */
	public static void sleep(long millis) {
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
		}
	}

	public static String unZip(String filePath, String unPath) {
		return RuntimeUtil.execCmd("unzip -o ".concat(filePath).concat(" -d ").concat(unPath),true,true);
	}
	
	public static String unGZip(String filePath, String unPath) {
		String ungz_cmd=String.format("gunzip -c %s >%s", filePath,unPath);
		return RuntimeUtil.execCmd(ungz_cmd,true,true);
	}

}
